package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.pojo.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/dish")
@Api("菜品管理")
public class DishController {
    @Autowired
    private DishService dishService;

    @PostMapping
    @ApiOperation(value = "菜品添加")
    public Result<String> addDish(@RequestBody DishDTO dishDTO){
        dishService.addDish(dishDTO);
        return Result.success();
    }

    @GetMapping("/page")
    @ApiOperation(value = "菜品分页查询")
    public Result<PageResult> findByPage(DishPageQueryDTO dto){
        PageResult result = dishService.findByPage(dto);
        return Result.success(result);
    }

    @DeleteMapping
    @ApiOperation(value = "菜品批量删除")
    public Result<String> deleteByIds(@RequestParam List<Long> ids,Integer status){
        dishService.deleteByIds(ids,status);
        return Result.success();
    }
    @GetMapping("/{dishId}")
    @ApiOperation(value = "菜品回显")
    public Result<DishVO> findById(@PathVariable Long dishId){
        DishVO dish = dishService.findById(dishId);
        return Result.success(dish);
    }

    @PutMapping
    @ApiOperation(value = "修改菜品")
    public Result<DishVO> update(@RequestBody DishDTO dishDTO){
        dishService.update(dishDTO);
        return Result.success();
    }

    @GetMapping("/list")
    @ApiOperation(value = "根据分类查询菜品")
    public Result<List<Dish>> findByCategory(Long categoryId){
        List<Dish> dishList = dishService.findByCategory(categoryId);
        return Result.success(dishList);
    }

    /**
     * 起售停售
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    @ApiOperation("菜品起售停售")
    public Result startOrStop(@PathVariable Integer status,Long id){
        dishService.startOrStop(status,id);
        return Result.success();
    }


}
